﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using BaseDll;
using MotionIoLib;
using Sunny.UI;
namespace OtherDevice
{
    [Description("程控电源")]
    public partial class Form_程控电源 : Form_ControlBase
    {
        private ProgramPowerBase powerBase = null;
        public Form_程控电源()
        {
            InitializeComponent();
        }
        public override void FlushToDlg(object devicebase)
        {
            try
            {
                if (devicebase == null)
                    return;
                this.powerBase = devicebase as ProgramPowerBase;
                this.Dock = DockStyle.Fill;
                this.Show();
            }
            catch (Exception)
            {

            }

        }
        private void OpenCKPower_Click(object sender, EventArgs e)
        {

            int num = ChannelChoose.Text == "CH1" ? 0 : 1;
            double valueVoltage = txt_V.Text.ToDouble(); ;
            powerBase.Power(true);
            powerBase.SetV(num, valueVoltage);

            double valueCurrent = txt_I.Text.ToDouble();
            powerBase.SetI(num, valueCurrent);
        }

        private void CloseCKPower_Click(object sender, EventArgs e)
        {

            powerBase.Power(false);

        }

        private void GetCurrent_Click(object sender, EventArgs e)
        {

            try
            {
                int num = ChannelChoose.Text == "CH1" ? 0 : 1;
                string r = "";
                double value = 0;
                if (!powerBase.GetI(num, ref value))
                    r = r + "获取电流失败";
                else
                    r = r + "电流:" + value.ToString();
                if (!powerBase.GetV(num, ref value))
                    r = r + "获取电压失败";
                else
                    r = r + "电压:" + value.ToString();

                txt_result.Text = r;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void PowerCtrl_Load(object sender, EventArgs e)
        {

        }
    }
}
